package com.hy.mydesktop.shared.persistence.domain.gxt;

import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.IndexColumn;

import net.sf.gilead.annotations.ServerOnly;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.ChangeEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.TreeModel;
import com.extjs.gxt.ui.client.widget.Component;
import com.hy.mydesktop.client.component.meta.GridColumnConfigModel;
import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

/**
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2010-8-27；时间：下午04:38:15</li>
 * <li>类型名称：GxtComponentMetaModel</li>
 * <li>设计目的：
 * GxtComponentMetaModel存储所以控件的元模型:分为普通结构和树形结构<br>
 * GxtComponentMetaModel迟绑定：gxtMetaModelTypeEnum用于判断GxtComponentMetaModel是属于BaseModel还是
 * 其子类TreeModel</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */

@Entity
@Table(name="t_gxt_Component_MetaNodeModel")
public class GxtComponentMetaNodeModel extends MyBaseModel{
	
	

	
	/**
	 * <ul>
	 * <li>开发作者：花宏宇</li>
	 * <li>设计日期：2010-8-29；时间：下午02:28:48</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long serialVersionUID = 6357423258767982589L;
	//private int leftValue;
	//private int rightValue;
	//private int parentLeftValue;
	
	
	/*
	ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS
	ComponentMetaDataConstants.CHILDREN_ITEMS
	ComponentMetaDataConstants.LAYOUT_INDEX
	ComponentMetaDataConstants.LAYOUT
	ComponentMetaDataConstants.WIDTH
	ComponentMetaDataConstants.HEIGHT
	ComponentMetaDataConstants.TITLE
	ComponentMetaDataConstants.RESIZABLE
	ComponentMetaDataConstants.MAXMIZABLE
	ComponentMetaDataConstants.MINMIZABLE	
	MetaDataConstants.TEXT		
	MetaDataConstants.LEFT_VALUE
	MetaDataConstants.RIGHT_VALUE			
	MetaDataConstants.COMPONENT_MODEL_TYPE 
	MetaDataConstants.COMPONENT_MODEL_TYPE_INDEX	
	*/
	

	
	
	
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")
	@IndexColumn(name="list_index")
	public List<GridColumnConfigModel> getGridColumnConfigModels() {
		return super.get(ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS);
	}

	public void setGridColumnConfigModels(List<GridColumnConfigModel> gridColumnConfigModels) {
		super.set(ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS, gridColumnConfigModels);
		////////////设置表格字段之后，则自动添加下列属性//////////////////////////////////////////
		super.set(ComponentMetaDataConstants.GRIDMODULE_TYPE, ComponentTypeEnum.GRIDMODULE_MODEL.toString());
		setChildrenItemsType("data");
	}
	
	//component data
	@Column(nullable=false)
	public String getChildrenItemsType() {
		return super.get(ComponentMetaDataConstants.CHILDREN_ITEMS_TYPE);
	}

	public void setChildrenItemsType(String childrenItemsType) {
		super.set(ComponentMetaDataConstants.CHILDREN_ITEMS_TYPE, childrenItemsType);
	}
	
	@OneToMany(cascade={CascadeType.REMOVE,CascadeType.ALL},fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")
	@IndexColumn(name="list_index")
	public List<ItemOfAssociateToWindow> getChildrenItems ( )
	{
		return this.get (ComponentMetaDataConstants.CHILDREN_ITEMS ) ;
	}
	
	public void setChildrenItems (List<ItemOfAssociateToWindow> childrenItems )
	{
		this.set (ComponentMetaDataConstants.CHILDREN_ITEMS,  childrenItems) ;
	}
	
		
	//@Transient
	@Enumerated(EnumType.STRING)
	@Column(nullable=true)
	@ServerOnly
	public ComponentTypeEnum getLayout() {
		return super.get(ComponentMetaDataConstants.LAYOUT);
	}

	public void setLayout(ComponentTypeEnum layout) {
		super.set(ComponentMetaDataConstants.LAYOUT, layout);
	}
	
	public int getLayoutIndex ( )
	{
		return this.get (ComponentMetaDataConstants.LAYOUT_INDEX ,0) ;
	}
	
	public void setLayoutIndex (int layoutIndex )
	{
		this.set (ComponentMetaDataConstants.LAYOUT_INDEX,  layoutIndex) ;
	}
	
	
	@Column(nullable=true)
	public int getWidth() {
		return super.get(ComponentMetaDataConstants.WIDTH,0);
	}

	public void setWidth(int width) {
		super.set(ComponentMetaDataConstants.WIDTH, width);
	}
	
	@Column(nullable=true)
	public int getHeight() {
		return super.get(ComponentMetaDataConstants.HEIGHT,0);
	}

	public void setHeight(int height) {
		super.set(ComponentMetaDataConstants.HEIGHT, height);
	}
	
	@Column(nullable=true)
	public String getTitle() {
		return super.get(ComponentMetaDataConstants.TITLE);
	}

	public void setTitle(String title) {
		super.set(ComponentMetaDataConstants.TITLE, title);
	}
	
	@Column(nullable=true)
	public Boolean getResizable() {
		return super.get(ComponentMetaDataConstants.RESIZABLE,true);
	}

	public void setresizable(Boolean resizable) {
		super.set(ComponentMetaDataConstants.RESIZABLE, resizable);
	}
	
	@Column(nullable=true)
	public Boolean getMaxmizable() {
		return super.get(ComponentMetaDataConstants.MAXMIZABLE,true);
	}

	public void setMaxmizable(Boolean maxmizable) {
		super.set(ComponentMetaDataConstants.MAXMIZABLE, maxmizable);
	}
	
	@Column(nullable=true)
	public Boolean getMinmizable() {
		return super.get(ComponentMetaDataConstants.MINMIZABLE);
	}

	public void setMinmizable(Boolean minmizable) {
		super.set(ComponentMetaDataConstants.MINMIZABLE, minmizable);
	}
//	@Transient

	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")
	public Set<GxtComponentMetaNodePorperty> getComponentProperties() {
		return super.get(MetaDataConstants.COMPONENT_PROPERTIES);
	}

	public void setComponentProperties(Set<GxtComponentMetaNodePorperty> componentProperties) {
		super.set(MetaDataConstants.COMPONENT_PROPERTIES, componentProperties);
	}
	
	public String getText() {
		return super.get(MetaDataConstants.TEXT);
	}

	public void setText(String text) {
		super.set(MetaDataConstants.TEXT, text);
	}
	
	public int getLeftValue() {
		return super.get(MetaDataConstants.LEFT_VALUE,0);
	}

	public void setLeftValue(int leftValue) {
		super.set(MetaDataConstants.LEFT_VALUE, leftValue);
	}

	public int getRightValue() {
		return super.get(MetaDataConstants.RIGHT_VALUE,0);
	}

	public void setRightValue(int rightValue) {
		super.set(MetaDataConstants.RIGHT_VALUE, rightValue);
	}
	
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：获取将要创建的控件Component的真实类型</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-8-28；时间：下午上午11:12:55</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	@Transient
	//@Enumerated(EnumType.STRING)
	//@Column(nullable=true)
	@ServerOnly
	public ComponentTypeEnum getComponentTypeEnum ( )
	{
		return this.get (MetaDataConstants.COMPONENT_MODEL_TYPE ) ;
	}
		
	

	/**
	 * 
	 * <ul>
	 * <li>方法含义：设置要创建的控件Component的真实类型</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-8-28；时间：下午上午11:13:57</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param componentTypeEnum
	 */
	public void setComponentTypeEnum (ComponentTypeEnum componentTypeEnum )
	{
		this.set (MetaDataConstants.COMPONENT_MODEL_TYPE,  componentTypeEnum) ;
	}
	

	@Column(nullable=true)
	public String getComponentTypeEnumName ( )
	{
		return this.get (MetaDataConstants.COMPONENT_MODEL_TYPE_NAME) ;
	}
	
	public void setComponentTypeEnumName (String componentTypeEnumName )
	{
		this.set (MetaDataConstants.COMPONENT_MODEL_TYPE_NAME,  componentTypeEnumName) ;
	}
	
	public int getComponentTypeEnumIndex ( )
	{
		return this.get (MetaDataConstants.COMPONENT_MODEL_TYPE_INDEX ,0) ;
	}
	
	public void setComponentTypeEnumIndex (int componentTypeEnumIndex )
	{
		this.set (MetaDataConstants.COMPONENT_MODEL_TYPE_INDEX,  componentTypeEnumIndex) ;
	}
	
	/**
	 * 构造函数
	 */
	public GxtComponentMetaNodeModel ( )
	{
		super ( ) ;
		
	}

	/**
	 * 构造函数
	 */
	public GxtComponentMetaNodeModel (Map < String , Object > properties )
	{
		super (
				properties ) ;
		//this.setLeftValue(1);
		//this.setRightValue(2);
		
	}

	/**
	 * 构造函数
	 */
	public GxtComponentMetaNodeModel (Map < String , Object > properties,int leftValue,int rightValue )
	{	
		super (
				properties ) ;
		/*if (leftValue<rightValue) {
			
			this.setLeftValue(leftValue);
			this.setRightValue(rightValue);
		} else {
			this.setLeftValue(1);
			this.setRightValue(2);
		}*/
		
	}
			
	
	/*@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	public GridModel getGridModel ( )
	{
		return this.get (ComponentMetaDataConstants.GRID_MODEL ) ;
	}
	
	public void setGridModel (GridModel gridModel )
	{
		this.set (ComponentMetaDataConstants.GRID_MODEL,  gridModel) ;
	}*/
	

	/*@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER
	,mappedBy="gxtComponentMetaNodeModel")
	public Set<ItemOfAssociateToWindow> getItemOfAssociateToWindows ( )
	{
	return this.get (ComponentMetaDataConstants.CHILDREN_ITEMS ) ;
	}
	
	public void setItemOfAssociateToWindows (Set<ItemOfAssociateToWindow> childrenItems )
	{
	this.set (ComponentMetaDataConstants.CHILDREN_ITEMS,  childrenItems) ;
	}*/
	
		
	/*@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")
	public Set<GridColumnConfigModel> getGridColumnConfigModels() {
		return super.get(ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS);
	}

	public void setGridColumnConfigModels(Set<GridColumnConfigModel> gridColumnConfigModels) {
		super.set(ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS, gridColumnConfigModels);
	}*/
	
	/*@OneToMany(cascade={CascadeType.REMOVE,CascadeType.ALL},fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")
	public Set<ItemOfAssociateToWindow> getChildrenItems ( )
	{
		return this.get (ComponentMetaDataConstants.CHILDREN_ITEMS ) ;
	}
	
	public void setChildrenItems (Set<ItemOfAssociateToWindow> childrenItems )
	{
		this.set (ComponentMetaDataConstants.CHILDREN_ITEMS,  childrenItems) ;
	}*/

	
}
